package org.nowcoder.leetcode.bit;

import java.util.HashMap;
import java.util.Map;

/**
 * Title  : 260. Single Number III
 * Source : https://leetcode.cn/problems/single-number-iii
 * Author : XrazYang
 * Date   : 2023-10-17
 */

public class LeetCode_260 {
    public int[] singleNumber(int[] nums) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            int val = map.getOrDefault(nums[i], 0);
            map.put(nums[i], val + 1);
        }
        Integer[] ele =
                map.entrySet().stream()
                        .filter(entry -> entry.getValue() == 1)
                        .map(Map.Entry::getKey)
                        .toList()
                        .toArray(new Integer[2]);
        return new int[]{ele[0], ele[1]};
    }
}
